#pragma once


#include"hash.h"

namespace HashBucket
{

	template<class K,class V>
	class mymap
	{
		struct MapKeyofT
		{
			const K& operator()(const pair<K,V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef HashTable<K, pair<const K, V>, MapKeyofT>  HT;
		typedef typename HashTable<K, pair<const K, V>, MapKeyofT>::Iterator iterator;
		typedef typename HashTable<K, pair<const K, V>, MapKeyofT>::const_Iterator const_iterator;


		iterator begin()
		{
			return _HT.Begin();
		}

		iterator end()
		{
			return _HT.End();
		}
		const_iterator begin() const
		{
			return _HT.Begin();
		}

		const_iterator end() const
		{
			return _HT.End();
		}
		pair<iterator, bool> insert(const pair<const K, V>& kv)
		{
			return _HT.Insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> p1 = insert(make_pair(key, V()));
			return p1.first->second;
		}


	private:

		HashTable<K, pair<const K,V>, MapKeyofT> _HT;
	};

	void testunorded_map()
	{
		mymap<string,int> map1;
		map1.insert({"a",1});
		map1.insert({ "b",10 });
		map1.insert({ "bcd",21});
		map1.insert({"efg",13});

		mymap<string,int>::iterator  it = map1.begin();


		while (it != map1.end())
		{
			
			cout << (*it).second << " ";
			++it;

		}
		cout << endl;
		map1["a"] += 1;
		map1["b"] += 1;
		map1["bcd"] += 1;
		map1["efg"] += 1;
		for (auto& e : map1)
		{
			
			cout << e.second << " ";
		}
		cout << endl;
		const mymap<string, int> map2(map1);
		mymap<string, int>::const_iterator it2 = map2.begin();
		while (it2 != map2.end())
		{

			cout << (*it2).second << " ";
			++it2;

		}

	}
}
